In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
from paths import *
%matplotlib inline
import pandas as pd
import seaborn as sns
import statsmodels.formula.api as smf
from sklearn.linear_model import LinearRegression
from sklearn import metrics
from sklearn.cross_validation import train_test_split
import numpy as np
/Users/GP1514/.pyenv/versions/anaconda3-2.5.0/lib/python3.5/site-packages/matplotlib/__init__.py:1350: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)
At Imperial
In [3]:
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('jpeg')
%config InlineBackend.figure_format = 'jpeg'
%config InlineBackend.rc = {'font.size': 10, 'figure.figsize': (6.0, 4.0), \
                            'figure.facecolor': (1, 1, 1, 0), 'savefig.dpi': 36, \
                            'figure.subplot.bottom': 0.125, 'figure.edgecolor': (1, 1, 1, 0)}
In [4]:
%%javascript
IPython.OutputArea.auto_scroll_threshold = 1000;
In [5]:
# instantiate utility class
gr = Graph()
In [6]:
mice = loadDataLight()
mouseA
mouseB
mouseM1217F
mouseM1223M
In [7]:
# gr.plotTF(mouseA, mask=False)
df = pd.DataFrame(columns=['mouse', 'exp', 'rep', 'cor', 'corR', 'corH', 'corR+corH'])
i=0
for mouse in mice.mice:
    for exp in mouse.experiments:
        for rep in exp.repeats:
            rep.getModels(mouseA.experiments[2].repeats[0].alpha)
            df.loc[i] = [mouse.name, int(exp.number), int(rep.number), rep.cor, rep.rmsR, rep.rmsH, rep.rms]
            i+=1
df['mouse'] = df['mouse'].astype('category')
df['exp'] = df['exp'].astype('int')
df['rep'] = df['rep'].astype('int')
In [8]:
# plt.plot(mouseB.experiments[2].meanAlphaModel)
In [35]:
gr.fRmin = 0
gr.fHmin = 0
gr.fHmax = 1400
gr.fRmax = 100


gr.plotModels(mouseM1223M, 0,0, mouseB.experiments[2].meanAlphaModel)
gr.plotModels(mouseM1223M, 0,0, mouseM1223M.experiments[0].repeats[0].alpha, 
             title=r'$\alpha$ FROM SAME SIGNAL')

p_est = [0.4121683, 1.09384498, 3.68435018,  0.98029149]
x = np.real(xax(mouseM1217F.experiments[0].repeats[0].mRatio, 60000))
alpha = [guess_function(xi,p_est[0],p_est[1],p_est[2]) for xi in x]
gr.plotModels(mouseM1223M, 0,0, alpha)
(0.39712185356-0.0847230272237j)
(0.4797966759+0.0530323335914j)
(0.532088178701-0.284156020395j)
(0.624754235075-0.331733802498j)
(0.346695757966-0.0220730553446j)
(0.34717135281-0.171449782944j)
In [24]:
df['mouse_cat'] = df.mouse.cat.codes
In [11]:
df[['mouse', 'mouse_cat']].drop_duplicates()
Out[11]:
mouse mouse_cat
0 mouseA 0
20 mouseB 1
40 mouseM1217F 2
92 mouseM1223M 3

Correlation between hemo and voltage mean signals

In [34]:
g = sns.FacetGrid(df, col="mouse_cat", size=4, aspect=.8)
g = g.map(sns.boxplot, "exp", "cor")
g.map(plt.axhline, y=0, ls=":", c="red")
plt.savefig(DIRECTORY + 'data-correlations.png')

Transfer function

In [13]:
alpha =  mouseB.experiments[2].meanAlphaModel
plt.plot(xax(alpha, len(alpha)*20), alpha)
plt.title('Model of transfer function chosen')
plt.savefig(DIRECTORY + 'alpha.png', dpi=300)

Correlation between data and reconstructed data

In [33]:
g = sns.FacetGrid(df, col="mouse_cat", size=4, aspect=.8)
g = g.map(sns.boxplot, "exp", "corR+corH")
g.map(plt.axhline, y=0, ls=":", c="red")

g = sns.FacetGrid(df, col="mouse_cat", size=4, aspect=.8)
g = g.map(sns.boxplot, "exp", "corR")
g.map(plt.axhline, y=0, ls=":", c="red")

g = sns.FacetGrid(df, col="mouse_cat", size=4, aspect=.8)
g = g.map(sns.boxplot, "exp", "corH")
g.map(plt.axhline, y=0, ls=":", c="red")

plt.savefig(DIRECTORY + 'model-correlations.png')